﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Silvermoon.Shapes
{
    /// <summary>
    /// Specifies the range of the characters to display.
    /// </summary>
    public struct TextSpriteRange
    {
        private int offset;
        private int length;

        public bool IsEmpty
        {
            get { return length == int.MaxValue; }
        }

        /// <summary>
        /// The first character to display.
        /// </summary>
        public int Offset { get { return offset; } }

        /// <summary>
        /// Number of characters to display.
        /// </summary>
        public int Length { get { return length; } }

        public TextSpriteRange(int offset, int length)
        {
            this.offset = offset;
            this.length = Math.Max(0, length);
        }

        public override bool Equals(object obj)
        {
            TextSpriteRange range = (TextSpriteRange)obj;
            return (range.length == length) && (range.offset == offset);
        }

        public static bool Equals(TextSpriteRange a, TextSpriteRange b)
        {
            return a.Equals(b);
        }

        public bool Equals(TextSpriteRange range)
        {
            return (range.length == length) && (range.offset == offset);
        }

        public override int GetHashCode()
        {
            return (length << 0x13) ^ offset;
        }

        public static bool operator ==(TextSpriteRange a, TextSpriteRange b)
        {
            return (a.length == b.length) && (a.offset == b.offset);
        }

        public static bool operator !=(TextSpriteRange a, TextSpriteRange b)
        {
            return (a.length != b.length) || (a.offset != b.offset);
        }

        public static readonly TextSpriteRange Empty = new TextSpriteRange(0, int.MaxValue);


    }
}
